#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>


void test01()
{
	int ch = fgetc(stdin);
	fputc(ch, stdout);
}

struct Person
{
	char name[10];
	int age;
};

void test02()
{
	struct Person p1 = { "lkm",19};
	fscanf(stdin,"%s %d", p1.name, &(p1.age));
	fprintf(stdout,"%s %d", p1.name, p1.age);

}

void test03()
{
	struct Person p1 = { "lkm",19 };

	FILE* pf = fopen("test.txt", "wb");
	if (pf == NULL)
	{
		perror("fopen");
		return -1;
	}

	fwrite(&p1, sizeof(p1), 1, pf);

	fclose(pf);
	pf = NULL;
}

void test04()
{
	struct Person p1 = {0};

	FILE* pf = fopen("test.txt", "rb");
	if (pf == NULL)
	{
		perror("fopen");
		return -1;
	}

	fread(&p1, sizeof(p1), 1, pf);
	printf("%s %d", p1.name, p1.age);
	fclose(pf);
	pf = NULL;
}

void test05()
{
	struct Person p = { "lkm",19 };
	char buf[20] = { 0 };
	sprintf(buf,"%s %d", p.name, p.age);
	printf("%s\n", buf);

	struct Person tmp = { 0 };
	sscanf(buf, "%s %d", tmp.name, &(tmp.age));
	printf("%s %d", tmp.name, tmp.age);
}

int main()
{
	//test01();
	//test02();
	//test03();
	//test04();
	test05();
	return 0;
}